# -*- coding: utf-8 -*-
# Vincent Foley-Bourgon (vfoley <at> gmail <dot> com)
# PyoPaint

import wx

from Measure import Measure

WIDTH = 1024
HEIGHT = 768

class GClefPanel(wx.Panel):
    """Simple panel with the G clef."""
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=(75,200))
        self.SetBackgroundColour('white')
        png = wx.Image("Resources/gclef.png").ConvertToBitmap()
        wx.StaticBitmap(self, -1, png)


class Staff(wx.ScrolledWindow):
    """A staff contains a list of measures."""
    def __init__(self, parent):
        wx.ScrolledWindow.__init__(self, parent, size=(WIDTH,240))
        self.SetScrollbars(1, 1, WIDTH, 240)
        self.boxSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizer(self.boxSizer)
        self.boxSizer.Add(GClefPanel(self), 0)
        self.measures = []

    def AddMeasure(self):
        measure = Measure(self)
        self.measures.append(measure)
        self.boxSizer.Add(measure, 0, wx.FIXED_MINSIZE|wx.ALL, 0)
        self.Layout()
        self.AdjustScrollbars()

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title="PyoPaint",
                          pos=(0,0), size=(WIDTH, HEIGHT))
        #self.mainPanel = wx.Panel(self)
        # Staff ne doit pas etre dans un panneau, qui n'est pas scrollable...
        self.staff = Staff(self)

        # A few initial measures
        for i in xrange(3):
            self.staff.AddMeasure()

        # Button to dynamically add new measures
        # Ajoute le bouton dans Staff... Devrait probablement aller dans une toolbar eventuellement
        self.btn = wx.Button(self.staff, -1, "+", pos=(800,500))
        self.Bind(wx.EVT_BUTTON, self.OnClick, self.btn)

    def OnClick(self, evt):
        self.staff.AddMeasure()
        # Feinte un resize de la fenetre pour que la scrollbar soit mise a jour.
        evt = wx.SizeEvent(self.GetSize(), self.GetId())
        self.ProcessEvent(evt)
        
